﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GUI_CLock
{
    class BinaryClock : ITimeObserver
    //BinaryClock generates the Binary clock view by instantiating 3 binary digits and updating them when notified by the model
    {
        const int XPOS = 20;
        const int YPOS = 10;
        const int XSIZE = 20;
        const int YSIZE = 20;
        const int STROKETHICKNESS = 3;

        private Binary_Digit digith;
        private Binary_Digit digitm;
        private Binary_Digit digits;

        Canvas canvas1;

        private int Hours, Minutes, Seconds;
        
        private ITimeSubject timemodel;


        public BinaryClock(ITimeSubject timemodel, Canvas canvas1)
        {

            this.canvas1 = canvas1;

            this.digith = new Binary_Digit(XPOS + 0 * (XSIZE + 18 * STROKETHICKNESS), YPOS, XSIZE, YSIZE, STROKETHICKNESS);
            this.digitm = new Binary_Digit(XPOS + 1 * (XSIZE + 18 * STROKETHICKNESS), YPOS, XSIZE, YSIZE, STROKETHICKNESS);
            this.digits = new Binary_Digit(XPOS + 2 * (XSIZE + 18 * STROKETHICKNESS), YPOS, XSIZE, YSIZE, STROKETHICKNESS);

            this.timemodel = timemodel;
            timemodel.RegisterObserver(this);
        }

        public void TimeUpdate(DateTime currentTime)
        {
            
            Hours = currentTime.Hour;
            if (Hours > 12) { Hours = Hours - 12; }
            if (Hours == 0) { Hours = 12; }

            Minutes = (int)(currentTime.Minute);

            Seconds = (int)(currentTime.Second);
            
            Display();
        }

        public void Display()
        {
            digith.displayDigit(Hours, canvas1);
            digitm.displayDigit(Minutes, canvas1);
            digits.displayDigit(Seconds, canvas1);

        }

    }
}
